<!--#include file="../nav/admin_top.php" -->
<style type="text/css">
a.del_type_a{
text-decoration:none;
color:#FF7777
}
a.del_type_a:hover{
text-decoration:none;
color:#FF0000;
background:#CCCCCC
}
a.add_child_a{
color:#CCCCCC;
text-decoration:none; 
line-height:25px;
 
}
a.add_child_a_on{
color:#FF6600;
text-decoration:none; 
line-height:25px; 
}
a.add_child_a:hover{
color:#FF6600;
}
.blankbar{
float:left;
background-color:#fcfcfc; 
border-bottom:1px dashed #CCCCCC;
height:20px;
width:80px;
margin-right:2px;
}
</style>
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">信息类别维护</span>
		<span class="totalSpan"> <label id="captionNum"></label> </span>
	</div> 
</div>
<div class="menuBg">
	<a class="menuReturn" href="{url::build('admin','index')}">返回管理首页</a> 
  <div style="clear:both"></div> 
</div>

<table class="innserTb" >
	<thead>
		<tr>
			<th style="width:100px">序号</th>
			<th >类别</th>
			<th style="width:100px">操作</th>
		</tr>
	</thead>
	<tbody id="mytypes">
		<?PHP
		
		
		/* 递归输出函数 */
		global $gi_type_num ;
		$gi_type_num=1;
		function type_show($rs,$level,$maxlevel){
			global  $gi_type_num;
			if(is_array($rs) && count($rs)>0){
				foreach($rs as $v){
					echo '
						<tr id="type_'.$gi_type_num.'" title="'.$gi_type_num.'" >
							<td >
								<input type="text" readonly="readonly" id="id_'.$gi_type_num.'" value="'.$v['id'].'" />
								<input type="text" class="textBoxShort" id="show_index_'.$gi_type_num.'" value="'.$gi_type_num.'" />
							</td>
							<td style="text-align:left">';
					$temp_i=0;		
					for($temp_i; $temp_i<$level ; $temp_i++){
						echo '<div class="blankbar"></div>';
					}
					echo '		
								<input type="hidden" class="textBoxDate" id="name_copy_'.$gi_type_num.'" value="'.$v['name'].'" />
								<input type="text" class="textBoxDate" id="name_'.$gi_type_num.'" value="'.$v['name'].'" />';
					if($level+1 < $maxlevel){
						echo ' <a class="add_child_a" href="javascript:void(0)" onclick="fnAdd('.$gi_type_num.')">添加子类</a>';
					}		
					echo '
							</td>
							<td >
								<a class="del_type_a" href="javascript:void(0)" onclick="fnDel('.$gi_type_num.')">  删除</a>
							</td>
						</tr>						
					';
					$gi_type_num++;
					if($level+1 < $maxlevel){
						type_show($v['childs'],$level+1,$maxlevel);
					}
				}
			}
		}
		type_show($types,0,10);
		?>
	</tbody>
	<tbody>
		<tr>
			<td></td>
			<td style="text-align:left">
				<a class="add_child_a_on" href="javascript:void(0)" onclick="fnAdd('')">添加顶级类别</a>
			</td>
			<td></td>
		</tr>
	</tbody>
</table>	
<div class="button_div">
	<button onclick="fnSave()">保 存</button>
	 
</div>
 
<script type="text/javascript">
var types = {json_encode($types)};
var maxlevel = 10;
$().ready(function(){
	o2js.build('ymprompt');
	showLoading();

	


	
});
/* 添加 */
function fnAdd(num){
	var str = prompt("请输入类别名称",'');
	var parent_id = 0;
	if(num != 0) parent_id=$('#id_'+num).val();
	if(str){
		$('button').attr('disabled','disabled');
		$.post(
			'/admin/pentype_add',
			{
				name:str,
				parent_id:parent_id
			},
			function(e){
				var ok = errorHandler(e);
				if(ok && ok.success=='1'){
					window.location.reload();
				}
				$('button').attr('disabled','');
			}
		); 
	} 
}
/* 删除 */
function fnDel(id){
	fnConfirm({
		str:'删除本行数据?',
		func_true:function(){
			$('button').attr('disabled','disabled');
			$.post(
				'/admin/type_del',
				{
					id:$('#id_'+id).val()
				},
				function(e){
					var ok = errorHandler(e);
					if(ok && ok.success=='1'){
						window.location.reload();
					}
					$('button').attr('disabled','');
				}
			);
		}
	}); 
} 
/* 保存 */
function fnSave(){
	var objs = [];
	/* mytypes */
	$('#mytypes tr').each(function(){
		var id = $(this).attr('title');
		objs.push({
			id:$('#id_'+id).val(),
			name:$('#name_'+id).val(),
			show_index:$('#show_index_'+id).val()
		});
	});
	for(var i=0; i<objs.length; i++){
		var obj = objs[i]; 
		if(obj.name == ''){
			alert('请填写完整类别名称！');
			return false;
		}
	}
	if(objs.length == 0){
		alert('没有任何可保存数据！');
		return false;
	}
	$('button').attr('disabled','disabled');
	$.post(
		'/admin/type_modify',
		{
			objs:JSON.encode(objs)
		},
		function(e){
			var ok = errorHandler(e);
			if(ok && ok.success == '1'){
				window.location.reload();
			} 
			$('button').attr('disabled','');
		}
	);
}
</script>
<!--#include file="../nav/admin_bottom.php" -->